﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TS_XY_Train_Repaire.Materials
{
    public partial class Sys_Setting_Station_WorkPlace_comprehensive : DevExpress.XtraEditors.XtraForm
    {
        public LeverString_SysOrganization _lt = new LeverString_SysOrganization();
        public  string LodeStr = "";
        public string Lode = "";
        public string id = "";
        public Sys_Setting_Station_WorkPlace_comprehensive()
        {
            InitializeComponent();
           
            //this.btn.Name = "";
            
        }
        public void Railway()
        {
            //f_id=TS_Win_Locomotive_MainForm.pUserInfoMain.UserRBID
            TS_Win_Class.FillListTypeAct(cb_f_rbid, "select f_id,f_name from  TS_S_T_P_RailwayBureau where f_del=0 order by f_id asc");
            TS_Win_Class.FillListTypeAct(cb_f_rsid, "select f_id,f_name,(select f_name from TS_S_T_P_RailwayBureau where TS_S_T_P_RailwayBureau.f_id=TS_S_T_P_RailwayStations.f_upid) as name1 from  TS_S_T_P_RailwayStations where f_del=0");
            //TS_Win_Class.FillListTypeAct(cb_f_type, "select f_uppid,f_name from TS_S_B_Station_WorkPlace_type  where f_del=0 order by f_id asc ");
        }  
        //private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //        id = cb_f_rbid.SelectedIndex.ToString();
        //        TS_Win_Class.FillListTypeAct(cb_f_rsid, "select f_id,f_name,(select f_name from TS_S_T_P_RailwayBureau where TS_S_T_P_RailwayBureau.f_id=TS_S_T_P_RailwayStations.f_upid) as name1 from  TS_S_T_P_RailwayStations where f_upid='" + id + "' and f_del=0 order by f_id asc");        
        // }

        private void Sys_Setting_Station_WorkPlace_comprehensive_Load(object sender, EventArgs e)
        {
            Railway();
            txt_f_name.Text = _lt.f_name;
            cb_f_type.SelectedIndex = Convert.ToInt16(_lt.f_type);
            cb_f_rbid.SelectedValue = Convert.ToInt16(_lt.f_rbid);
            cb_f_rsid.SelectedValue = Convert.ToInt16(_lt.f_rsid);
            txt_f_stack.Text = _lt.f_stack;
            txt_f_stacknum.Text = _lt.f_stacknum;
            this.btn.Text = LodeStr;
            this.btn.Name = Lode;
       
            this.btn.Text = LodeStr;
        }

        private void btn_Click(object sender, EventArgs e)
        {
            string strSql = "";
            switch(this.btn.Name){
                case "barAddNodes":
                    if (_lt.f_id.ToString()=="M-1")
                    {
                        strSql = "insert into TS_S_B_Station_WorkPlace(f_name,f_rbid,f_rsid,f_type,f_level,f_deep,f_stack,f_stacknum) values('" + txt_f_name.Text.Trim() + "','" + cb_f_rbid.SelectedValue + "','" + cb_f_rsid.SelectedValue + "','" + cb_f_type.SelectedIndex + "',',','0','" + txt_f_stack.Text.Trim() + "','" + txt_f_stacknum.Text.Trim() + "') ";
                    }
                    else {
                        string _level = "";
                        int _deep = -1;
                        _level = _lt.f_level + _lt.f_id+",";
                        _deep = Convert.ToInt32(_lt.f_deep)+1;
                        strSql = "insert into TS_S_B_Station_WorkPlace(f_name,f_rbid,f_rsid,f_type,f_level,f_deep,f_stack,f_stacknum) values('" + txt_f_name.Text.Trim() + "','" + cb_f_rbid.SelectedValue + "','" + cb_f_rsid.SelectedValue + "','" + cb_f_type.SelectedIndex + "','" + _level + "','" + _deep + "','" + txt_f_stack.Text.Trim() + "','" + txt_f_stacknum.Text.Trim() + "') ";                  
                    }
                    TS_Win_Class.MySqlCom(strSql);
                     MessageBox.Show("添加数据成功","提示");
                     ClaerAll();
                     this.Close();
                     this.DialogResult = DialogResult.OK;
                    break;
                case "barEditNodes":
                    strSql = "update TS_S_B_Station_WorkPlace set f_name='" + txt_f_name.Text.Trim() + "',f_rbid='" + cb_f_rbid.SelectedValue + "',f_rsid='" + cb_f_rsid.SelectedValue + "',f_type='" + cb_f_type.SelectedIndex + "',f_stack='" + txt_f_stack.Text.Trim() + "',f_stacknum='" + txt_f_stacknum.Text.Trim() + "' where f_id='" + _lt.f_id.ToString() + "'";
                    TS_Win_Class.MySqlCom(strSql);
                    MessageBox.Show("修改成功", "提示");
                    this.Close();
                    this.DialogResult = DialogResult.OK;
                    break;
                default:
                    MessageBox.Show("");
                    break;
            
            }
        }

        public void ClaerAll() {

            txt_f_name.Text = "";
            txt_f_stack.Text = "";
            txt_f_stacknum.Text = "";
            cb_f_rbid.SelectedText = "";
            cb_f_rsid.SelectedText = "";
            cb_f_type.SelectedText = "";
            
        }

        private void Sys_Setting_Station_WorkPlace_comprehensive_FormClosing(object sender, FormClosingEventArgs e)
        {
            TS_Win_Locomotive_MainForm.htActionItem.Remove(this.Name);
        }

        private void cb_f_rbid_SelectedIndexChanged(object sender, EventArgs e)
        {
            id = cb_f_rbid.SelectedIndex.ToString();
            TS_Win_Class.FillListTypeAct(cb_f_rsid, "select f_id,f_name,(select f_name from TS_S_T_P_RailwayBureau where TS_S_T_P_RailwayBureau.f_id=TS_S_T_P_RailwayStations.f_upid) as name1 from  TS_S_T_P_RailwayStations where f_upid='" + id + "' and f_del=0 order by f_id asc");        
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
